
function [dfdt] = waves_benchmark(t,y)
global U  h  g  dx x Q;

dx1=1/dx;
dx2 = 1/(dx*dx);

% ---- Construct the spatial Discretization Matrix------%
A = zeros(x,x);
A(1,x) = -U*0.5*dx1;
A(1,2) =  U*0.5*dx1;
for k=2:x-1
    A(k,k-1) = -U*0.5*dx1;
    A(k,k+1) =  U*0.5*dx1;
end

A(x,x-1) = -U*0.5*(1/dx);
A(x,1)   =  U*0.5*(1/dx);

L=zeros(2*x,2*x);
L(x+1:2*x,x+1:2*x)=A;
L(1:x,1:x)=A;

L(1,2*x)   = h*dx2;
L(1,x+2)   = h*dx2;
L(x,x+1)   = h*dx2;
L(x,2*x-1) = h*dx2;
for k=1:x
    L(k,x+k)= -2*h*dx2;
    L(x+k,k)=g;
end

for k=2:x-1
    L(k,x+k-1) = h*dx2;
    L(k,x+k+1)= h*dx2;
end
%
Q =L;
dfdt = -L*y;
